<template>
  <el-card class="page-container">
    <template #header>
      <div class="header">
        <span>完善教师信息</span>
      </div>
    </template>
    <el-form :model="teacherInfo" :rules="rules" ref="teacherForm" label-width="100px">
      <el-form-item label="教师姓名" prop="teacherName">
        <el-input v-model="teacherInfo.teacherName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { updateTeacherInfo } from '@/api/userInfoService.js'
import useUserInfoStore from '@/stores/userInfo.js'
import { useRouter } from 'vue-router'

const router = useRouter()
const userInfoStore = useUserInfoStore()

const teacherInfo = ref({
  teacherName: '',
})

const rules = {
  teacherName: [{ required: true, message: '请输入教师姓名', trigger: 'blur' }],
}

const submitForm = async () => {
  try {
    const result = await updateTeacherInfo(teacherInfo.value)
    if (result.code === 0) {
      ElMessage.success(result.msg || '保存成功')

    } else {
      ElMessage.error(result.msg || '保存失败')
    }
  } catch (error) {
    ElMessage.error('请求失败，请我重试')
  }
}

const resetForm = () => {
  teacherInfo.value = {
    teacherName: '',
  }
}

</script>

<style lang="scss" scoped>
.page-container {
  max-width: 500px;
  margin: 20px auto;
}

.header {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 20px;
}
</style>
